package com.project.controller;

import com.project.bean.UserBean;
import com.project.service.IUserSerivce;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author(王思翰)
 * @Description(类的描述)
 * @Date(创建时间) 2021/8/2 11:04
 */
@RestController
@RequestMapping("user")
public class UserController {

    @Autowired
    private IUserSerivce serivce;

    /**
     * 登录验证
     * @param name 用户名
     * @param pwd 密码
     * @param request
     * @return 验证是否通过
     */
    @RequestMapping("login")
    public String login(String name, String pwd, HttpServletRequest request){
        UserBean userBean=serivce.login(name,pwd);
        if (userBean!=null){
            request.getSession().setAttribute("loginUserBean",userBean);
            return userBean.getPower();
        }else {
            return "no";
        }
    }

    @RequestMapping("getLoginUser")
    public UserBean getLoginUser(HttpServletRequest request){
        return (UserBean) request.getSession().getAttribute("loginUserBean");
    }
}
